window.tabs=window.tabs || [];
window.activeTab=typeof(window.activeTab)=="number"?window.activeTab:-1;

function previewTab(offset){try{
	
	if(offset==activeTab){
		closePreviewTab(offset);
		return;
	}

	var o=document.querySelector("#overlay");
	
	if(!tabs[offset].preview || tabs[offset].preview.width!=o.width || tabs[offset].preview.height!=o.height){
		tabs[offset].preview.width=o.width;
		tabs[offset].preview.height=o.height;
		if(offset!=activeTab)
			tabs[offset].tab.setAttribute("class","tab active");
		tabs[offset].preview.getContext("2d").drawWindow(tabs[offset].tab.contentWindow,0,0,o.width,o.height,"#ffffff");
		if(offset!=activeTab)
			tabs[offset].tab.setAttribute("class","tab inactive");
	}
	
	o.style.display="block";
	var ctx=o.getContext("2d");
	
	ctx.save();
	
	ctx.clearRect(0,0,o.width,o.height);
	ctx.globalAlpha=.8;
	ctx.drawImage(tabs[offset].preview,0,0);
	
	ctx.restore();
}catch(e){trace(e);}}

function closePreviewTab(offset){try{
	var o=document.querySelector("#overlay");
	o.style.display="none";
}catch(e){trace(e);}}

function onResize(evt){try{
	var o=document.querySelector("#overlay");
	var b=document.querySelector("#xulwindow");
	
	var r=b.getBoundingClientRect();
	var st=window.getComputedStyle(b);
	o.width=r.width-st.borderLeftWidth.replace(/[a-z]/g,"")-st.borderRightWidth.replace(/[a-z]/g,"");
	o.height=r.height-st.borderTopWidth.replace(/[a-z]/g,"")-st.borderBottomWidth.replace(/[a-z]/g,"");
}catch(e){trace(e);}}